package entity;

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


import sql_class.Subject;
import util.DBUtil;
import dao.SubjectDao;

public class LookSubject implements SubjectDao{

	@Override
	public List<Subject> getAll(int greadeid) {
		List<Subject> list = new ArrayList<Subject>();
		String sql = "select * from subject where gradeid=? ";
		PreparedStatement st = null;
		ResultSet rs = null;
		Connection con = DBUtil.open();
		
		try {
			st = con.prepareStatement(sql);
			st.setInt(1,greadeid);
			rs = st.executeQuery();
			Subject gd=null;
			while (rs.next()){	
				gd= new Subject();			
				gd.setGradeid(rs.getInt("gradeid"));
				gd.setSubjectname(rs.getString("subjectname"));
				list.add(gd);
			}
			return list;
		} catch (SQLException e) {
			
			e.printStackTrace();
		}		
		
		return null;
	}

}
